package com.socket_hpu;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class client {
    public static void main(String[] args) throws Exception {
        Socket s = new Socket("127.0.0.1", 8080);
        System.out.println("连接成功!");
        InputStream in = s.getInputStream();
        OutputStream out = s.getOutputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        PrintWriter writer = new PrintWriter(out, true);
//        writer.println("你好服务器!");
//        String res = br.readLine();
//        System.out.println("服务器说:"+ res);

            writer.println("你好,服务端!");
            String str = br.readLine();
            System.out.println("服务器说:" + str);
            String str1 = br.readLine();
        while (true) {
            System.out.print("==============游戏环节==============\n" + str1 + "\n该你出拳了:");
            String str2 = br.readLine();
            Scanner sc = new Scanner(System.in);
            String res = sc.next();
            writer.println(res);
            System.out.println("等待对方出拳...");
            System.out.println("服务端出了:" + str2);
            if (res.equals("石头") && str2.equals("剪刀")) {
                System.out.println("你赢了");
            } else if (res.equals("石头") && str2.equals("石头")) {
                System.out.println("平局");
            } else if (res.equals("石头") && str2.equals("布")) {
                System.out.println("你输了");
            } else if (res.equals("剪刀") && str2.equals("石头")) {
                System.out.println("你输了");
            } else if (res.equals("剪刀") && str2.equals("布")) {
                System.out.println("你赢了");
            } else if (res.equals("剪刀") && str2.equals("剪刀")) {
                System.out.println("平局");
            } else if (res.equals("布") && str2.equals("剪刀")) {
                System.out.println("你输了");
            } else if (res.equals("布") && str2.equals("石头")) {
                System.out.println("你赢了");
            } else if (res.equals("布") && str2.equals("布")) {
                System.out.println("平局");
            } else if (!res.equals("布") && !res.equals("剪刀") && !res.equals("石头")) {
                System.out.println("你的输入非法！！！你输了!!!");
            } else if (!str2.equals("布") && !str2.equals("剪刀") && !str2.equals("石头")) {
                System.out.println("对方输入非法！！！你赢了!!!");
            }
        }
//        in.read();
//        byte[] buffer = new byte[1024];
//        File f = new File("E:/xxx.jpg");
//        if (f.exists());
//            f.delete();
//        f.createNewFile();
//        FileOutputStream file = new FileOutputStream(f);
//        int i = in.read(buffer);
//        while (i>0) {
//            file.write(buffer, 0, i);
//            i = in.read();
//        }
//        file.close();
//        in.close();
//        System.out.println("复制成功");
    }
}
